<html> 
<head> 
<title>Select Database</title> 
</head> 
<body> 
<?php 

$debug= 1;
$vclass=$_POST['fclass']; 
$vorder=$_POST['order'];
$vphylum=$_POST['phylum'];


$username = "fossilplot";
$password = "fossilplot";
$hostname = "localhost"; 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
 or die("Unable to connect to MySQL");


//select a database to work with
$selected = mysql_select_db("fossilplot",$dbhandle)
  or die("Could not select examples");

$clause_class = "(";
for($i=0;$i<sizeof($_POST["fclass"]);$i++) {
$result = mysql_query("select id from class where class_name='$vclass[$i]'");
while ($row = mysql_fetch_array($result)) {
$a[$i][0]=$vclass[$i];
$a[$i][1]= $row{'id'};
if($clause_class=="("){
   $clause_class = $clause_class.$row{'id'};
  //print "hello";
}
else{$clause_class = $clause_class.",".$row{'id'};}

}
print $vclass[$i];
print "<br>";
}

$clause_class= $clause_class.")";
//if($debug==1){
print_r ($a);
print "clause class is ".$clause_class."<br>";
//}

$clause_order = "(";
for($i=0;$i<sizeof($_POST["order"]);$i++) {
$result = mysql_query("select id from fossilplot.order where order_name='$vorder[$i]'");
while ($row = mysql_fetch_array($result)) {
$b[$i][0]=$vorder[$i];
$b[$i][1]= $row{'id'};
if($clause_order=="("){
   $clause_order = $clause_order.$row{'id'};
  //print "hello";
}
else{$clause_order = $clause_order.",".$row{'id'};}
}
print $vorder[$i];
print "<br>";
}

$clause_order= $clause_order.")";

echo "array b is: ";
print_r ($b);
print "clause order is ".$clause_order."<br>";


$clause_phylum = "(";
for($i=0;$i<sizeof($_POST["phylum"]);$i++) {
$result = mysql_query("select id from fossilplot.phylum where phylum_name='$vphylum[$i]'");
while ($row = mysql_fetch_array($result)) {
$c[$i][0]=$vphylum[$i];
$c[$i][1]= $row{'id'};
if($clause_phylum=="("){
   $clause_phylum = $clause_phylum.$row{'id'};
  //print "hello";
}
else{$clause_phylum = $clause_phylum.",".$row{'id'};}
}
print $vphylum[$i];
print "ddd<br>";
}

echo "array c is: ";
print_r ($c);
$clause_phylum= $clause_phylum.")";
print "clause phylum is ".$clause_phylum."<br>";

echo "<table boder=1>";
$result = mysql_query("select * from genus where class_id in $clause_class and order_id in $clause_order and phylum_id in $clause_phylum;");

//$result = mysql_query("select * from genus where order_id in $clause_order;");

while ($row = mysql_fetch_array($result)) {
if(debug){
for($i=0; $i<sizeof($a); $i++){
		  if ($a[$i][1]==$row{'class_id'}){$tmpa=$a[$i][0];}
}

for($i=0; $i<sizeof($b); $i++){
		  if ($b[$i][1]==$row{'order_id'}){$tmpb=$b[$i][0];}
}

for($i=0; $i<sizeof($c); $i++){
		  if ($c[$i][1]==$row{'phylum_id'}){$tmpc=$c[$i][0];}
}
print "<tr><td>".$row{'genus_name'}."</td>"."<td>".$tmpa."</td>"."<td>".$tmpb."</td>"."<td>".$tmpc."</td>"."</tr>";
//print "<tr><td>".$row{'genus_name'}."</td>"."<td>".$tmpb."</td>"."</tr>";
}
}


echo "</table>";

mysql_close($dbhandle);

?>
</body> 
</html>